package com.glsc.ngateway.flowable.listener.createproduct;

import com.glsc.ngateway.flowable.service.FlowableUserService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Arrays;

@Component
public class CreateProductStartHandler implements TaskListener {

    public static CreateProductStartHandler createProductStartHandler;
    @Autowired
    private FlowableUserService flowableUserService;

    @PostConstruct
    public void init() {
        createProductStartHandler = this;
        createProductStartHandler.flowableUserService = this.flowableUserService;
    }


    @Override
    public void notify(DelegateTask delegateTask) {

        //delegateTask.setAssignee("老板");
        String userid = delegateTask.getVariable("userid").toString();
        String content = delegateTask.getVariable("content").toString();

//        String department = createProductStartHandler.flowableUserService.getDepartment(userid);
//        delegateTask.setVariable("teamleader", createProductStartHandler.flowableUserService.getLeader(userid));
//        delegateTask.setVariable("manager", createProductStartHandler.flowableUserService.getManager(department));
//
//        JSONObject json = JSONObject.parseObject(content);
//        delegateTask.setVariable("days", json.getString("days"));

        String[] v = {"lm1", "lm2", "lm3"};
        delegateTask.setVariable("prepareUserList", Arrays.asList(v));
        delegateTask.setVariable("prepareUserListSize", v.length);

        String[] v1 = {"lm1", "lm2", "lm3"};
        delegateTask.setVariable("accountUserList", Arrays.asList(v1));
        delegateTask.setVariable("accountUserListSize", v1.length);

        String[] v2 = {"lm1", "lm2", "lm3"};
        delegateTask.setVariable("infoUserList", Arrays.asList(v2));
        delegateTask.setVariable("infoUserListSize", v2.length);

        String[] v3 = {"lm1", "lm2", "lm3"};
        delegateTask.setVariable("beforeCollectUserList", Arrays.asList(v3));
        delegateTask.setVariable("beforeCollectUserListSize", v3.length);

        String[] v4 = {"lm1", "lm2", "lm3"};
        delegateTask.setVariable("confirmCollectUserList", Arrays.asList(v4));
        delegateTask.setVariable("confirmCollectUserListSize", v4.length);

        String[] v5 = {"lm1", "lm2", "lm3"};
        delegateTask.setVariable("setupUserList", Arrays.asList(v5));
        delegateTask.setVariable("setupUserListSize", v5.length);

        String[] v6 = {"lm1", "lm2", "lm3"};
        delegateTask.setVariable("archiveUserList", Arrays.asList(v6));
        delegateTask.setVariable("archiveUserListSize", v6.length);
    }

}